home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / DXF.TRM < prev    next >
Text File  |  1992-03-25  |  10KB  |  278 lines

  1. /*
  2.  * $Id: dxf.trm,v 3.26 92/03/24 22:34:49 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - dxf.trm */
  6. /*
  7.  * Copyright (C) 1991, 1992
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted,
  11.  * provided that the above copyright notice appear in all copies and
  12.  * that both that copyright notice and this permission notice appear
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed
  17.  * as patches to released version.
  18.  *
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  *
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   AutoCad (Release 10.x) dxf file format (import with AutoCad dxfin command)
  25.  *
  26.  *
  27.  * AUTHOR
  28.  *   Florian Hiss  (fhis1231@w204zrz.zrz.tu-berlin.de)
  29.  *
  30.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  31. */
  32.  
  33. #define DXF_UNIT 60.0
  34. #define LINEWIDTH 0.0351  /* default line width is 1 pt */
  35.  
  36. /* 120 (autocad units) wide by 80 (autocad units) high (default)
  37.    use the GNUPLOT 'set size' command to change the defaults */
  38. #define DXF_XMAX (120.0 * DXF_UNIT)
  39. #define DXF_YMAX (80.0 * DXF_UNIT)
  40. #define DXF_HTIC (0.01 * DXF_XMAX)  /* 1.0 percent */
  41. #define DXF_VTIC (0.01 * DXF_YMAX)  /* 1.0 percent */
  42. #define DXF_HCHAR (0.014 * DXF_XMAX) /* 1.4 percent */
  43. #define DXF_VCHAR (0.026 * DXF_YMAX) /* 2.6 percent */
  44. #define DXF_TEXTHEIGHT (0.7 * DXF_VCHAR) /* actual text height */
  45. #define DXF_TEXTWIDTH (0.7 * DXF_HCHAR) /* actual text width,
  46.  only a guess, we don't know the width of a character of given height
  47.  of the AutoCad STANDARD text font, so change it if you like */
  48. #define DXF_LINE_TYPES 7 /* number of line types we support. see below  */
  49. #define MAX_LAYER 7  /* number of layers used for the drawing. see below */
  50. #define LT_SCALE 1  /* line type scaling */
  51.  
  52. static unsigned int DXF_posx;
  53. static unsigned int DXF_posy;
  54. static unsigned int dxf_linetype; /* linetype is mapped to a layer. see below. */
  55. enum JUSTIFY dxf_justify = LEFT;
  56. static float dxf_angle = 0.0; /* either 0 (horizontal) or 90.0 (vertical) */
  57.  
  58. /* text style used in the entire drawing */
  59. static char *text_style = "STANDARD";
  60. /* text always resides on layer 0 */
  61. #define TEXT_LAYER 0
  62. /* each linetype resides on its own layer. each layer has its own color.
  63.    this avoids difficulties that AutoCad has with proper scaling of
  64.    the linetypes.
  65.    change the colors according to your needs */
  66. static char *layer_name[] = {"0","1","2","3","4","5","6"};
  67. /* the colours are white, red, yellow, green, cyan, blue, magenta.
  68.    change them according to your needs.
  69.    when using a black and white plotting device the colours map to different
  70.    line thicknesses. see description of AutoCad print / plot command */
  71. static char *layer_colour[] = {"7","1","2","3","4","5","6"};
  72. /* support line types AutoCad has to offer by default. */
  73. static char *layer_lines[] = {"CONTINUOUS","DASHED","HIDDEN","CENTER","PHANTOM",
  74.                 "DOT","DASHDOT"};
  75.  
  76. static BOOLEAN vector_was_last = FALSE;
  77.  
  78. DXF_init()
  79. {
  80.     DXF_posx = DXF_posy = 0;
  81.     dxf_linetype = 0;
  82.     dxf_angle = 0.0;
  83.     vector_was_last = FALSE;
  84. }
  85.  
  86. DXF_graphics()
  87. {
  88.     register struct termentry *t = &term_tbl[term];
  89.     int i;
  90.  
  91.     fprintf(outfile,"999\n");
  92.     fprintf(outfile,"%% GNUPLOT: dxf file for AutoCad\n");
  93.     fprintf(outfile,"  0\nSECTION\n  2\nHEADER\n");
  94.     fprintf(outfile,"  9\n$EXTMIN\n");
  95.     fprintf(outfile," 10\n0.000\n 20\n0.000\n");
  96.     fprintf(outfile,"  9\n$EXTMAX\n");
  97.     fprintf(outfile," 10\n%-6.3f\n 20\n%-6.3f\n",t->xmax/DXF_UNIT,t->ymax/DXF_UNIT);
  98.     fprintf(outfile,"  9\n$LIMMIN\n");
  99.     fprintf(outfile," 10\n0.000\n 20\n0.000\n");
  100.     fprintf(outfile,"  9\n$LIMMAX\n");
  101.     fprintf(outfile," 10\n%-6.3f\n 20\n%-6.3f\n",t->xmax/DXF_UNIT,t->ymax/DXF_UNIT);
  102.     fprintf(outfile,"  9\n$TEXTSTYLE\n  7\n%s\n",text_style);
  103.     fprintf(outfile,"  9\n$TEXTSIZE\n 40\n%-6.3f\n",DXF_TEXTHEIGHT/DXF_UNIT);
  104.     fprintf(outfile,"  9\n$PLINEWID\n 40\n%-6.4f\n",LINEWIDTH);
  105.     fprintf(outfile,"  9\n$LTSCALE\n  40\n%-6.3f\n",LT_SCALE);
  106.     fprintf(outfile,"  9\n$COORDS\n 70\n  1\n");
  107.     fprintf(outfile,"  9\n$CELTYPE\n 6\nBYLAYER\n"); /* entity line type name */
  108.     fprintf(outfile,"  9\n$CLAYER\n  8\n0\n"); /* current layer */
  109.     fprintf(outfile,"  9\n$CECOLOR\n 62\n   %s\n",layer_colour[0]);
  110.     fprintf(outfile,"  9\n$MENU\n  1\nacad\n");
  111.     fprintf(outfile,"  0\nENDSEC\n");
  112.     fprintf(outfile,"  0\nSECTION\n  2\nTABLES\n");
  113.     /* the linetype table */
  114.     fprintf(outfile,"0\nTABLE\n  2\nLTYPE\n 70\n    %d\n",DXF_LINE_TYPES);
  115.     fprintf(outfile,"0\nLTYPE\n  2\nCONTINUOUS\n 70\n    64\n");
  116.     fprintf(outfile,"  3\nSolid line\n 72\n    65\n 73\n      0\n 40\n0.0\n");
  117.     fprintf(outfile,"  0\nLTYPE\n  2\nDASHED\n 70\n    64\n");
  118.     fprintf(outfile,"  3\n__ __ __ __ __ __ __ __ __ __ __ __ __ __ __\n");
  119.     fprintf(outfile," 72\n    65\n 73\n     2\n 40\n0.75\n 49\n0.5\n 49\n-0.25\n");
  120.     fprintf(outfile,"  0\nLTYPE\n  2\nHIDDEN\n 70\n    64\n");
  121.     fprintf(outfile,"  3\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\n");
  122.     fprintf(outfile," 72\n    65\n 73\n     2\n 40\n0.375\n 49\n0.25\n 49\n-0.125\n");
  123.     fprintf(outfile,"  0\nLTYPE\n  2\nCENTER\n 70\n    64\n");
  124.     fprintf(outfile,"  3\n____ _ ____ _ ____ _ ____ _ ____ _ ____ _ ____\n");
  125.     fprintf(outfile," 72\n    65\n 73\n     4\n 40\n2.0\n 49\n1.25\n 49\n-0.25\n");
  126.     fprintf(outfile," 49\n0.25\n 49\n-0.25\n");
  127.     fprintf(outfile,"  0\nLTYPE\n  2\nPHANTOM\n 70\n    64\n");
  128.     fprintf(outfile,"  3\n_____ _ _ _____ _ _ _____ _ _ _____ _ _ ____\n");
  129.     fprintf(outfile," 72\n    65\n 73\n     6\n 40\n2.5\n 49\n1.25\n");
  130.     fprintf(outfile," 49\n-0.25\n 49\n0.25\n 49\n-0.25\n 49\n0.25\n 49\n-0.25\n");
  131.     fprintf(outfile,"  0\nLTYPE\n  2\nDOT\n 70\n    64\n");
  132.     fprintf(outfile,"  3\n...............................................\n");
  133.     fprintf(outfile," 72\n    65\n 73\n     2\n 40\n0.25\n 49\n0.0\n 49\n-0.25\n");
  134.     fprintf(outfile,"  0\nLTYPE\n  2\nDASHDOT\n 70\n    64\n");
  135.     fprintf(outfile,"  3\n__ . __ . __ . __ . __ . __ . __ . __ . __ . __\n");
  136.     fprintf(outfile," 72\n    65\n 73\n     4\n 40\n1.0\n 49\n0.5\n 49\n-0.25\n");
  137.     fprintf(outfile," 49\n0.0\n 49\n-0.25\n");
  138.     fprintf(outfile,"  0\nENDTAB\n");
  139.     /* the layer table */
  140.     fprintf(outfile,"  0\nTABLE\n  2\nLAYER\n 70\n   %-d\n",MAX_LAYER);
  141.     for (i = 1; i <= MAX_LAYER; i++)
  142.         fprintf(outfile,"  0\nLAYER\n  2\n%s\n 70\n   64\n62\n   %s\n  6\n%s\n",
  143.             layer_name[i-1],layer_colour[i-1],layer_lines[i-1]);
  144.     fprintf(outfile,"  0\nENDTAB\n0\nENDSEC\n");
  145.     /* no blocks for insertion */
  146.     fprintf(outfile,"  0\nSECTION\n  2\nBLOCKS\n  0\nENDSEC\n");
  147.     /* start the entity section */
  148.     fprintf(outfile,"  0\nSECTION\n");
  149.     fprintf(outfile,"  2\nENTITIES\n");
  150. }
  151.  
  152. DXF_text()
  153. {
  154.     if (vector_was_last) fprintf(outfile,"  0\nSEQEND\n");
  155.     fprintf(outfile,"  0\nENDSEC\n  0\nEOF\n");
  156. }
  157.  
  158. DXF_linetype(linetype)
  159.     int linetype;
  160. {
  161.     linetype = abs(linetype);
  162.     linetype = linetype%DXF_LINE_TYPES;
  163.     dxf_linetype = linetype;
  164. }
  165.  
  166. DXF_move(x, y)
  167.     unsigned int x, y;
  168. {
  169.     DXF_posx = x;
  170.     DXF_posy = y;
  171.     if (vector_was_last) fprintf(outfile,"  0\nSEQEND\n");
  172.     vector_was_last = FALSE;
  173.     fprintf(outfile,"  0\nPOLYLINE\n  8\n%s\n 66\n   1\n",layer_name[dxf_linetype]);
  174.     fprintf(outfile,"  6\n%s\n",layer_lines[dxf_linetype]);
  175.     fprintf(outfile,"  0\nVERTEX\n  8\n%s\n",layer_name[dxf_linetype]);
  176.     fprintf(outfile,"  6\n%s\n",layer_lines[dxf_linetype]);
  177.     fprintf(outfile," 10\n%-6.3f\n 20\n%-6.3f\n 30\n0.000\n",DXF_posx/DXF_UNIT,DXF_posy/DXF_UNIT);
  178. }
  179.  
  180. DXF_vector(ux, uy)
  181.     unsigned int ux, uy;
  182. {
  183.     DXF_posx = ux;
  184.     DXF_posy = uy;
  185.     vector_was_last = TRUE;
  186.     fprintf(outfile,"  0\nVERTEX\n  8\n%s\n",layer_name[dxf_linetype]);
  187.     fprintf(outfile,"  6\n%s\n",layer_lines[dxf_linetype]);
  188.     fprintf(outfile,"  10\n%-6.3f\n  20\n%-6.3f\n  30\n0.000\n",
  189.                     DXF_posx/DXF_UNIT,DXF_posy/DXF_UNIT);
  190. }
  191.  
  192. DXF_put_text(x, y, str)
  193.     int x, y;
  194.     char str[];
  195. {
  196.     int stl;
  197.     float xleftpos, yleftpos, xrightpos,yrightpos;
  198.     /* ignore empty strings */
  199.     if (str[0] == '\0') return;
  200.  
  201.     stl = 0; while (str[stl] != '\0') ++stl; /* get string length */
  202.  
  203.     if (vector_was_last) fprintf(outfile,"  0\nSEQEND\n");
  204.     vector_was_last = FALSE;
  205.     fprintf(outfile,"  0\nTEXT\n  8\n%s\n",layer_name[TEXT_LAYER]);
  206.     if (dxf_angle != 90.0)
  207.     {
  208.        switch (dxf_justify)
  209.        {
  210.            case LEFT  : xleftpos = (float) x;
  211.                  yleftpos = (float)(y-DXF_VCHAR/4.0);
  212.                  xrightpos = (float)(x+stl*DXF_TEXTWIDTH);
  213.                  yrightpos = yleftpos; break;
  214.            case RIGHT : xleftpos = (float)(x-stl*DXF_TEXTWIDTH);
  215.                  yleftpos = (float)(y-DXF_VCHAR/4.0);
  216.                  xrightpos = (float) x;
  217.                  yrightpos = yleftpos; break;
  218.         case CENTRE: xleftpos = (float)(x-stl*DXF_TEXTWIDTH/2.0);
  219.                  yleftpos = (float)(y-DXF_VCHAR/4.0);
  220.                  xrightpos = (float) x;  /* center point */
  221.                  yrightpos = yleftpos;
  222.                  break;
  223.         }
  224.     }
  225.     else
  226.     {
  227.         switch (dxf_justify)
  228.         {
  229.            case LEFT  : xleftpos = (float)(x+DXF_VCHAR/4.0);
  230.                  yleftpos = (float) y;
  231.                  xrightpos = xleftpos;
  232.                  yrightpos = (float)(y+stl*DXF_TEXTWIDTH); break;
  233.            case RIGHT : xleftpos = (float)(x+DXF_VCHAR/4.0);
  234.                  yleftpos = (float)(y-stl*DXF_HCHAR);
  235.                  xrightpos = xleftpos;
  236.                  yrightpos = (float) y; break;
  237.         case CENTRE: xleftpos = (float)(x+DXF_VCHAR/4.0);
  238.                  yleftpos = (float)(y-stl*DXF_TEXTWIDTH/2.0);
  239.                  xrightpos = xleftpos;
  240.                  yrightpos = (float) y;  /* center point */
  241.                  break;
  242.         }
  243.     }
  244.     fprintf(outfile," 10\n%-6.3f\n 20\n%-6.3f\n 30\n0.000\n",
  245.                 xleftpos/DXF_UNIT,yleftpos/DXF_UNIT);
  246.     fprintf(outfile," 40\n%-6.3f\n  1\n%s\n 50\n%-6.3f\n",
  247.             DXF_TEXTHEIGHT/DXF_UNIT,str,dxf_angle);
  248.     fprintf(outfile,"  7\n%s\n",text_style);
  249.     if (dxf_justify != LEFT)
  250.     {
  251.         fprintf(outfile," 72\n%d\n",dxf_justify);
  252.         fprintf(outfile," 11\n%-6.3f\n 21\n%-6.3f\n 31\n0.000\n",
  253.                 xrightpos/DXF_UNIT,yrightpos/DXF_UNIT);
  254.     }
  255. }
  256.  
  257. DXF_text_angle(angle)
  258.     int angle;
  259. {
  260.     dxf_angle = 0.0;
  261.     if (angle == 1) dxf_angle = 90.0;
  262.     return(TRUE);
  263. }
  264.  
  265. DXF_justify_text(mode)
  266.     enum JUSTIFY mode;
  267. {
  268.     dxf_justify = mode;
  269.     return(TRUE);
  270. }
  271.  
  272. DXF_reset()
  273. {
  274.     DXF_posx = DXF_posy = 0;
  275. }
  276.  
  277.  
  278.